package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.ApartmentInfo;
import com.atguigu.lease.model.entity.GraphInfo;
import com.atguigu.lease.model.entity.LabelInfo;
import com.atguigu.lease.model.entity.ViewAppointment;
import com.atguigu.lease.web.app.mapper.GraphInfoMapper;
import com.atguigu.lease.web.app.mapper.LabelInfoMapper;
import com.atguigu.lease.web.app.mapper.RoomInfoMapper;
import com.atguigu.lease.web.app.mapper.ViewAppointmentMapper;
import com.atguigu.lease.web.app.service.ApartmentInfoService;
import com.atguigu.lease.web.app.service.ViewAppointmentService;
import com.atguigu.lease.web.app.vo.apartment.ApartmentItemVo;
import com.atguigu.lease.web.app.vo.appointment.AppointmentDetailVo;
import com.atguigu.lease.web.app.vo.appointment.AppointmentItemVo;
import com.atguigu.lease.web.app.vo.graph.GraphVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author liubo
 * @description 针对表【view_appointment(预约看房信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment>
        implements ViewAppointmentService {

    @Autowired
    private LabelInfoMapper labelInfoMapper;

    @Autowired
    private GraphInfoMapper graphInfoMapper;

    @Autowired
    private RoomInfoMapper roomInfoMapper;
    @Autowired
    private ViewAppointmentMapper viewAppointmentMapper;
    @Autowired
    private ApartmentInfoService apartmentInfoService;

    @Override
    public List<AppointmentItemVo> queryByUerId(Long userId) {
        List<AppointmentItemVo> appointmentItemVoList = viewAppointmentMapper.queryByUerId(userId);
        return appointmentItemVoList;
    }


        @Override
        public AppointmentDetailVo CustomGetDetailById(Long id){
            //1.判断是否被其他管理员删除
            ViewAppointment viewAppointment = getById(id);
            if (ObjectUtils.isEmpty(viewAppointment)) {
                return null;
            }
            //2.查询预约id相关联公寓基本信息
            ApartmentInfo apartmentInfo = apartmentInfoService.getById(viewAppointment.getApartmentId());
            List<LabelInfo> labelInfoList = labelInfoMapper.queryByapartId(viewAppointment.getApartmentId());
            List<GraphInfo> graphInfoList = graphInfoMapper.queryByapartId(viewAppointment.getApartmentId());
            BigDecimal minRent = roomInfoMapper.findMinRentByapartId(viewAppointment.getApartmentId());
            ApartmentItemVo apartmentItemVo = new ApartmentItemVo();
            apartmentItemVo.setLabelInfoList(labelInfoList);
            apartmentItemVo.setMinRent(minRent);
            apartmentItemVo.setGraphVoList(graphInfoList);
            BeanUtils.copyProperties(apartmentInfo,apartmentItemVo);
            //3.捏到一起
            AppointmentDetailVo appointmentDetailVo = new AppointmentDetailVo();
            BeanUtils.copyProperties(viewAppointment, appointmentDetailVo);
            appointmentDetailVo.setApartmentItemVo(apartmentItemVo);

            return appointmentDetailVo;
        }
    }





